package loader;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import gameobj.ElementType;
import gameobj.SpawnPoint;
import manager.ElementManager;
import manager.ImageManager;

public class Loader {
	
	static public void load(String filename)
	{
		ImageManager im = ImageManager.get();
		ElementManager em = ElementManager.get();
		
		im.addImage("image/background/9.jpg");
		im.addImage("image/enemy/4.png");
		im.addImage("image/play/11.png");
		im.addImage("image/fire/16.png");
		im.addImage("image/fire/13.png");
		im.addImage("image/boss/4.png");
		im.addImage("image/fire/10.png");
		
		File file = new File (filename);
		int data;
		try {
			FileInputStream fis = new FileInputStream (file);
			String str = "";
			while( (data = fis.read()) != -1 )
			{
				str += (char)data;
			}
			SpawnPoint sp = new SpawnPoint ();
			em.add(ElementType.SPAWNPOINT, sp);
			String [] type = str.split(";");
			for(String s:type)
			{
				String []typeset = s.split("=");
				String key = typeset[0];
				String [] values = typeset[1].split(",");
				for(String value:values)
				{
					sp.add(Integer.parseInt(value), key);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}

